package com.joey.cloud.provider.service;

import com.joey.cloud.communal.constant.BaseConstant;
import com.joey.cloud.communal.utils.ResponseUtil;
import com.joey.cloud.provider.cache.CacheFeignService;
import com.joey.cloud.provider.dic.DicFeignService;
import com.joey.cloud.provider.elasticsearch.EsFeignService;
import com.joey.cloud.provider.psn.PsnFeignService;
import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 统一服务提供
 * @author joey
 */
@Data
@Component
public class BaseProviderService {
    @Resource
    private CacheFeignService cacheFeignService;
    @Resource
    private EsFeignService esFeignService;
    @Resource
    private PsnFeignService psnFeignService;
    @Resource
    private DicFeignService dicFeignService;


    /**
     * 字典注解调用
     * @param type
     * @param key
     * @param o
     * @return
     */
    public String queryDicText(String type, String key, Object o) {
        String text = null;
        ResponseUtil res = null;
        if(BaseConstant.DIC_TYPE1.equals(type)){
            //翻译数据字典
            res = dicFeignService.queryTextByKey(key,String.valueOf(o));
        }else if(BaseConstant.DIC_TYPE2.equals(type)){
            //翻译用户名称
            res = psnFeignService.queryPersonNameById(String.valueOf(o));
        }
        if(res!=null && res.getData()!=null){
            text = String.valueOf(res.getData());
        }
        return text;
    }
}
